const fs = require('fs')
const path = require('path')

const excludes = ['.git', 'dist', 'node_modules', 'public'].map(_ => {
  return path.resolve(__dirname, _)
})

function stat (extnames) {
  const dirs = fs.readdirSync(__dirname)
  let count = 0
  const fn = (dirs, parDir) => {
    for (let i = 0; i < dirs.length; i++) {
      const dir = path.resolve(parDir, dirs[i])
      if (fs.statSync(dir).isDirectory()) {
        if (!excludes.includes(dir)) {
          fn(fs.readdirSync(dir), dir)
        }
      } else if (extnames.includes(dir.split('.').pop())) {
        count += fs.readFileSync(dir).toString('utf-8').split('\n').length
      }
    }
  }
  fn(dirs, __dirname)
  return count
}

console.log('工程源代码总行数：', stat(['js', 'css', 'scss', 'vue']))
